#include <iostream>
#include <cstdio>

#define N 110

using namespace std;

char a[N][N];
int ans = 0;
int n, m;

void dfs(int x, int y){
    a[x][y] = '.';
    int xx, yy;
    for(int dx = -1; dx <= 1; dx++){
        for(int dy = -1; dy <= 1; dy++){
            xx = x + dx; yy = y + dy;
            if(xx > 0 && xx <= n && yy > 0 && yy <= m && a[xx][yy] == 'W'){
                dfs(xx, yy);
            }
        }
    }
    return;
}

int main(){
    cin >> n >> m;
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= m; j++){
            cin >> a[i][j];
        }
    }
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= m; j++){
            if(a[i][j] == 'W'){
                dfs(i, j);
                ans++;
            }
        }
    }
    cout << ans;
    return 0;
}